package cn.fscode.code.generator.repository;

import cn.fscode.code.generator.mapper.TemplateGroupMapper;
import cn.fscode.code.generator.model.po.TemplateGroupPO;
import cn.fscode.code.generator.model.req.TemplateGroupListReq;
import cn.fscode.commons.tool.core.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author shenguangyang
 */
@Repository
public class TemplateGroupRepository extends ServiceImpl<TemplateGroupMapper, TemplateGroupPO>
                                        implements IService<TemplateGroupPO> {
    public List<TemplateGroupPO> listTemplateGroup(TemplateGroupListReq req) {
        LambdaQueryWrapper<TemplateGroupPO> wrapper = new LambdaQueryWrapper<TemplateGroupPO>()
                .like(StringUtils.isNotEmpty(req.getGroupName()), TemplateGroupPO::getGroupName, req.getGroupName())
                .orderByDesc(TemplateGroupPO::getCreateTime);
        return this.list(wrapper);
    }
}
